//
//  Scroll_PageControlView.m
//  RedManStock
//
//  Created by lanou3g on 15/7/20.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "Scroll_PageControlView.h"
#import "UIDefine.h"
@implementation Scroll_PageControlView

@synthesize pageControl,num;

- (instancetype)initWithFrame:(CGRect)frame
                       images:(NSArray *)imageArrary{
    
    if (self=[super initWithFrame:frame]) {
        
        self.num=imageArrary.count;
        self.index=0;
        self.buttonArray=[NSMutableArray array];
        
        
        _scrollView=[[UIScrollView alloc]initWithFrame:frame];
        _scrollView.delegate=self;
        _scrollView.pagingEnabled=YES;
        _scrollView.bounces=NO;
        _scrollView.showsHorizontalScrollIndicator=NO;
        
        //    设置scrollView可滑动区域是6个屏幕宽度
        _scrollView.contentSize=CGSizeMake(num*frame.size.width, frame.size.height);
        
        for (int i=0; i<num; i++) {
            
            UIButton *button=[UIButton buttonWithFrame:CGRectMake(i*frame.size.width, 0, frame.size.width, frame.size.height) normalImage:imageArrary[i]];
            
            //设置为NO，就不会出现button点击高亮时候图片变暗的效果了!!!
            button.adjustsImageWhenHighlighted=NO;
            button.tag=4000+i;
            
            [_scrollView addSubview:button];
            [self.buttonArray addObject:button];
//            UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(i*frame.size.width, 0, frame.size.width, frame.size.height)];
            
//            imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"v6_guide_%d",i+1]];
            //        给最后一页添加手势,这个手势就在视图里了
        
        }
        
        pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, frame.size.height*15/16, 30*num, 20)];
        pageControl.center=CGPointMake(frame.size.width/2, frame.size.height*15/16);
        pageControl.numberOfPages=num;
        pageControl.pageIndicatorTintColor=[UIColor colorWithWhite:0.300 alpha:1.000];
        pageControl.currentPageIndicatorTintColor=[UIColor whiteColor];
//        pageControl.alpha=0.4;
        
        
        [self addSubview:_scrollView];
        [self addSubview:pageControl];
        
    }
    return self;
    
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    _index=(NSInteger)(scrollView.contentOffset.x/self.frame.size.width);
    pageControl.currentPage=_index;
}


@end
